package com.zhongwang.mms.module.jiaGongSemi.controller;

import com.zhongwang.mms.base.BaseController;
import com.zhongwang.mms.common.JsonResult;
import com.zhongwang.mms.gen.entity.User;
import com.zhongwang.mms.module.half.model.HInBillModel;
import com.zhongwang.mms.module.half.model.HInventoryQueryModel;
import com.zhongwang.mms.module.half.model.HOrderDetailModel;
import com.zhongwang.mms.module.half.service.HBasicService;
import com.zhongwang.mms.module.half.service.OutOfAluminWarService;
import com.zhongwang.mms.module.half.service.OutOfBuyWarService;
import com.zhongwang.mms.module.jiaGongSemi.model.JSemiDetail;
import com.zhongwang.mms.module.jiaGongSemi.model.JSemiInBillModel;
import com.zhongwang.mms.module.jiaGongSemi.model.JSemiInventory;
import com.zhongwang.mms.module.jiaGongSemi.service.AluminiumInService;
import com.zhongwang.mms.module.jiaGongSemi.service.AluminiumOutService;
import com.zhongwang.mms.module.jiaGongSemi.service.SemiOutService;
import com.zhongwang.mms.util.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @description: 铝料出库
 * @author: th
 * @time: 2020/6/12 10:53
 */
@Controller
@RequestMapping("/aluminiumOut")
public class AluminiumOutController extends BaseController {

    @Autowired
    private HBasicService hBasicService;
    @Autowired
    private SemiOutService semiOutService;
    @Autowired
    private OutOfAluminWarService outOfAluminWarService;
    @Autowired
    private AluminiumOutService aluminiumOutService;

    // 创建入库单页面
    @GetMapping("/page")
    public String create(Model model) {

        // 获取登入用户实体
        User user = ShiroUtils.getUser();
        model.addAttribute("userName", user.getName());
        model.addAttribute("dept", hBasicService.getDept());
        model.addAttribute("odrDate", new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
        return  "jiaGongSemi/aluminiumOut/page";
    }

    // 库存列表
    @ResponseBody
    @PostMapping("/list")
    public JsonResult stockList(JSemiInventory query){

        startPage();
        List<JSemiDetail> list = semiOutService.outOfFinishWar(query);
        return jsonResult(list);
    }

    /**
     * 铝料出库单保存
     * @param jSemiInBillModel
     * @return
     */
    @ResponseBody
    @PostMapping("/create")
    public JsonResult create(@RequestBody JSemiInBillModel jSemiInBillModel) {

        return aluminiumOutService.saveHInBillModel(jSemiInBillModel);
    }
}
